<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="../utilities/master-calendar.xsl"/>
<xsl:import href="../utilities/date-and-time.xsl"/>
<xsl:import href="../utilities/get-admin-menu.xsl"/>
<xsl:import href="../utilities/get-client-info.xsl"/>

<xsl:param name="parent-root" select="concat($root,'/calendar')"/>
<xsl:param name="current-root" select="concat($root,'/calendar','/day')"/>

<xsl:template match="data">
	<xsl:param name="is-today">
		<xsl:choose>
			<xsl:when test="not($year) or $year='today' or $today = concat($year,'-',$month,'-',$day)">1</xsl:when>
			<xsl:otherwise>0</xsl:otherwise>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="not-month">
		<xsl:choose>
			<xsl:when test="not($month)">1</xsl:when>
			<xsl:otherwise>0</xsl:otherwise>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="not-day">
		<xsl:choose>
			<xsl:when test="not($day)">1</xsl:when>
			<xsl:otherwise>0</xsl:otherwise>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="date">
		<xsl:choose>
			<xsl:when test="not($year) or $year='today'">
				<xsl:value-of select="$today"/>
			</xsl:when>
			<xsl:when test="$year and not($month)">
				<xsl:value-of select="concat($year,'-01-01')"/>
			</xsl:when>
			<xsl:when test="$year and $month and not($day)">
				<xsl:value-of select="concat($year,'-',$month,'-01')"/>
			</xsl:when>
			<xsl:when test="$year and $month and $day">
				<xsl:value-of select="concat(format-number($year,'0000'),'-',format-number($month,'00'),'-',format-number($day,'00'))"/>
			</xsl:when>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="day">
		<xsl:choose>
			<xsl:when test="not($year) or $year='today'">
				<xsl:value-of select="substring($date,9,2)"/>
			</xsl:when>
			<xsl:when test="$month and not($day)">
				<xsl:value-of select="substring($date,9,2)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="format-number($day,'00')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="month">
		<xsl:choose>
			<xsl:when test="not($year) or $year='today'">
				<xsl:value-of select="substring($date,6,2)"/>
			</xsl:when>
			<xsl:when test="not($month) and $year!='today'">
				<xsl:value-of select="'01'"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="format-number($month,'00')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="year">
		<xsl:choose>
			<xsl:when test="not($year) or $year='today'">
				<xsl:value-of select="substring($date,1,4)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="format-number($year,'0000')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="month-days">
		<xsl:call-template name="month-days">
			<xsl:with-param name="year" select="$year"/>
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="next-month-days">
		<xsl:call-template name="next-month-days">
			<xsl:with-param name="year" select="$year"/>
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="previous-month-days">
		<xsl:call-template name="previous-month-days">
			<xsl:with-param name="year" select="$year"/>
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="previous-day">
		<xsl:call-template name="previous-day">
			<xsl:with-param name="date" select="$date"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="next-day">
		<xsl:call-template name="next-day">
			<xsl:with-param name="date" select="$date"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="previous-week">
		<xsl:call-template name="previous-week">
			<xsl:with-param name="date" select="$date"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="next-week">
		<xsl:call-template name="next-week">
			<xsl:with-param name="date" select="$date"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="current-date-url">
		<xsl:choose>
			<xsl:when test="$is-today = 1">
				<xsl:value-of select="concat($year,'/',$month,'/',$day,'/')"/>
			</xsl:when>
			<xsl:when test="$year and $not-month = 1">
				<xsl:value-of select="concat($year,'/')"/>
			</xsl:when>
			<xsl:when test="$year and $month and $not-day = 1">
				<xsl:value-of select="concat($year,'/',$month,'/')"/>
			</xsl:when>
			<xsl:when test="$year and $month and $day = 0">
				<xsl:value-of select="concat($year,'/',$month,'/')"/>
			</xsl:when>
			<xsl:when test="$year and $month and $day &gt; 0">
				<xsl:value-of select="concat($year,'/',$month,'/',$day,'/')"/>
			</xsl:when>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="previous-day-url">
		<xsl:value-of select="concat(substring($previous-day,1,4),'/',substring($previous-day,6,2),'/',substring($previous-day,9,2))"/>
	</xsl:param>
	<xsl:param name="next-day-url">
		<xsl:value-of select="concat(substring($next-day,1,4),'/',substring($next-day,6,2),'/',substring($next-day,9,2))"/>
	</xsl:param>
	<xsl:param name="previous-week-url">
		<xsl:value-of select="concat(substring($previous-week,1,4),'/',substring($previous-week,6,2),'/',substring($previous-week,9,2))"/>
	</xsl:param>
	<xsl:param name="next-week-url">
		<xsl:value-of select="concat(substring($next-week,1,4),'/',substring($next-week,6,2),'/',substring($next-week,9,2))"/>
	</xsl:param>
	<xsl:param name="previous-year-url">
		<xsl:choose>
			<xsl:when test="$is-today = 1">
				<xsl:value-of select="concat($year - 1,'/',$month,'/',substring($date,9,2))"/>
			</xsl:when>
			<xsl:when test="$year and $not-month = 1">
				<xsl:value-of select="$year - 1"/>
			</xsl:when>
			<xsl:when test="$year and $month and $not-day = 1">
				<xsl:value-of select="concat($year - 1,'/',$month)"/>
			</xsl:when>
			<xsl:when test="$year and $month and $day and $day = 0">
				<xsl:value-of select="concat($year - 1,'/',$month)"/>
			</xsl:when>
			<xsl:when test="$year and $month and $day and $day > 0">
				<xsl:value-of select="concat($year - 1,'/',$month,'/',$day)"/>
			</xsl:when>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="next-year-url">
		<xsl:choose>
			<xsl:when test="$is-today = 1">
				<xsl:value-of select="concat($year + 1,'/',$month,'/',substring($date,9,2))"/>
			</xsl:when>
			<xsl:when test="$year and $not-month = 1">
				<xsl:value-of select="$year + 1"/>
			</xsl:when>
			<xsl:when test="$year and $month and $not-day = 1">
				<xsl:value-of select="concat($year + 1,'/',$month)"/>
			</xsl:when>
			<xsl:when test="$year and $month and $day and $day = 0">
				<xsl:value-of select="concat($year + 1,'/',$month)"/>
			</xsl:when>
			<xsl:when test="$year and $month and $day and $day > 0">
				<xsl:value-of select="concat($year + 1,'/',$month,'/',$day)"/>
			</xsl:when>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="previous-month-url">
		<xsl:choose>
			<xsl:when test="$month - 1 &lt; 1">
				<xsl:choose>
					<xsl:when test="$is-today = 1">
						<xsl:value-of select="concat($year - 1,'/12/',substring($date,9,2))"/>
					</xsl:when>
					<xsl:when test="($year and $not-month = 1) or ($year and $month and $not-day = 1)">
						<xsl:value-of select="concat($year - 1,'/12')"/>
					</xsl:when>
					<xsl:when test="$year and $month and $day">
						<xsl:value-of select="concat($year - 1,'/12/',$day)"/>
					</xsl:when>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="$is-today = 1">
						<xsl:value-of select="concat($year,'/',format-number($month - 1,'00'),'/',substring($date,9,2))"/>
					</xsl:when>
					<xsl:when test="$year and $not-month = 1">
						<xsl:value-of select="concat($year,'/',format-number($month - 1,'00'))"/>
					</xsl:when>
					<xsl:when test="$year and $month and $not-day = 1">
						<xsl:value-of select="concat($year,'/',format-number($month - 1,'00'))"/>
					</xsl:when>
					<xsl:when test="$year and $month and $day = 0">
						<xsl:value-of select="concat($year,'/',format-number($month - 1,'00'))"/>
					</xsl:when>
					<xsl:when test="$year and $month and $day &gt; 0 and $day &lt;= $previous-month-days">
						<xsl:value-of select="concat($year,'/',format-number($month - 1,'00'),'/',$day)"/>
					</xsl:when>
					<xsl:when test="$year and $month and $day &gt; $previous-month-days">
						<xsl:value-of select="concat($year,'/',format-number($month - 1,'00'),'/',$previous-month-days)"/>
					</xsl:when>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="next-month-url">
		<xsl:choose>
			<xsl:when test="$month + 1 &gt; 12">
				<xsl:choose>
					<xsl:when test="$is-today = 1">
						<xsl:value-of select="concat($year + 1,'/01/',substring($date,9,2))"/>
					</xsl:when>
					<xsl:when test="($year and $not-month = 1) or ($year and $month and $not-day = 1)">
						<xsl:value-of select="concat($year + 1,'/01')"/>
					</xsl:when>
					<xsl:when test="$year and $month and $day">
						<xsl:value-of select="concat($year + 1,'/01/',$day)"/>
					</xsl:when>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="$is-today = 1">
						<xsl:value-of select="concat($year,'/',format-number($month + 1,'00'),'/',substring($date,9,2))"/>
					</xsl:when>
					<xsl:when test="$year and $not-month = 1">
						<xsl:value-of select="concat($year,'/',format-number($month + 1,'00'))"/>
					</xsl:when>
					<xsl:when test="$year and $month and $not-day = 1">
						<xsl:value-of select="concat($year,'/',format-number($month + 1,'00'))"/>
					</xsl:when>
					<xsl:when test="$year and $month and $day = 0">
						<xsl:value-of select="concat($year,'/',format-number($month + 1,'00'))"/>
					</xsl:when>
					<xsl:when test="$year and $month and $day &gt; 0 and $day &lt;= $next-month-days">
						<xsl:value-of select="concat($year,'/',format-number($month + 1,'00'),'/',$day)"/>
					</xsl:when>
					<xsl:when test="$year and $month and $day &gt; $next-month-days">
						<xsl:value-of select="concat($year,'/',format-number($month + 1,'00'),'/',$next-month-days)"/>
					</xsl:when>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="previous-month-date">
		<xsl:choose>
			<xsl:when test="$month - 1 &lt; 1">
				<xsl:value-of select="concat($year - 1,'-12-00')"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat($year,'-',format-number($month - 1,'00'),'-00')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="next-month-date">
		<xsl:choose>
			<xsl:when test="$month + 1 &gt; 12">
				<xsl:value-of select="concat($year + 1,'-01-00')"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat($year,'-',format-number($month + 1,'00'),'-00')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="week-day">
		<xsl:call-template name="get-day-of-the-week-name">
			<xsl:with-param name="date" select="$date"/>
		</xsl:call-template>
	</xsl:param>
	
	
	<xsl:choose>
		<xsl:when test="$year = 'NaN' or $year &lt; 1001 or $year &gt; 3000 or $month &gt; 12 or $month &lt; 1 or $day &gt; 31 or $day &lt; 1">
			<div class="grid_8 error">
				<h2>Calendar</h2>
				<p>Please enter a date in the address fields in the form of /calendar/yyyy/mm/dd/ to view a calendar. Or you can find out what the date is <a href="{$parent-root}/day/today/">today</a>. (This calendar does not calculate dates previous to 1,001 AD or greater than 3,000 AD.)</p>
			</div>
		</xsl:when>
		<xsl:otherwise>
			<div class="grid_16">
				<div class="grid_5 alpha">
<!-- xxxx FIXIN' HERE xxxx -->
					<xsl:choose>
						<xsl:when test="/data/clients/entry/administrator = 'Yes'">
							<xsl:call-template name="admin-menu"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:call-template name="client-info"/>
						</xsl:otherwise>
					</xsl:choose>
				</div>
				<xsl:choose>
					<xsl:when test="/data/clients/entry/client-status/item/@handle != 'active'">
						<div class="grid_10 omega">
							<div class="calendar-head">
								<h2>
									<xsl:text>Sorry, but your account has been </xsl:text>
									<strong>
										<xsl:value-of select="/data/clients/entry/client-status/item"/>
									</strong>
								</h2>
								<p>You are only permitted to view your current <a href="{$root}/profile">Profile</a> information and <a href="{$root}/archives">Archives</a> of past appointments. Please contact <xsl:value-of select="$website-name"/> directly at <strong>(541) 231-1118</strong> if you wish to schedule an appointment.</p>
							</div>
						</div>
					</xsl:when>
					<xsl:otherwise>
						<div class="grid_11 omega">
							<div class="calendar-head">
								<h2>
									<xsl:value-of select="normalize-space($week-day)"/>
									<xsl:text>, </xsl:text>
									<xsl:call-template name="get-formatted-date">
										<xsl:with-param name="date" select="$date"/>
									</xsl:call-template>
								</h2>
							</div>
							<div class="calendar-head">
								<ul class="calendar-menu">
									<li id="day_prev">
										<a href="{$current-root}/{$previous-day-url}/">Previous Day</a>
									</li>
									<li id="month_view">
										<a href="{$parent-root}/{$current-date-url}">Month</a>
									</li>
									<li id="day_next">
										<a href="{$current-root}/{$next-day-url}/">Next Day</a>
									</li>
								</ul>
							</div>
							<div class="calendar-day">
								<xsl:call-template name="calendar-day">
									<xsl:with-param name="year" select="substring($date,1,4)"/>
									<xsl:with-param name="month" select="substring($date,6,2)"/>
									<xsl:with-param name="day" select="substring($date,9,2)"/>
								</xsl:call-template>
							</div>
						</div>
					</xsl:otherwise>
				</xsl:choose>
			</div>
		</xsl:otherwise>
	</xsl:choose>
		
</xsl:template>
<xsl:template name="calendar-day">
	<xsl:param name="year" select="$year"/>
	<xsl:param name="month" select="$month"/>
	<xsl:param name="day" select="$day"/>
	<xsl:param name="date" select="concat($year,'-',$month,'-',$day)"/>
	<xsl:param name="this-month-day" select="substring(translate($date, '-', ''),5)"/>
	<xsl:param name="week-day">
		<xsl:call-template name="get-day-of-the-week-name">
			<xsl:with-param name="date" select="$date"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="is-holiday">
		<xsl:for-each select="iCalendar/vcalendar[@x-wr-calname='Holidays']/vevent[substring(dtstart,5) = $this-month-day][not(rrule/item/@class='byday') and rrule/item[@class='freq']='yearly']">
			<xsl:if test="substring(dtstart,5) = $this-month-day">1</xsl:if>
		</xsl:for-each>
	</xsl:param>
	<xsl:param name="is-vacation">
		<xsl:for-each select="/data/vacations/entry">
			<xsl:if test="date-of-closure = $date">1</xsl:if>
		</xsl:for-each>
	</xsl:param>
	<xsl:param name="is-past">
		<xsl:choose>
			<xsl:when test="translate($date, '-', '') &lt;= translate($today, '-', '')">1</xsl:when>
		</xsl:choose>
	</xsl:param>
	
	<xsl:param name="next-day">
		<xsl:call-template name="next-day">
			<xsl:with-param name="date" select="$today"/>
		</xsl:call-template>
	</xsl:param>
	
	<table summary="calendar" cellpadding="0" cellspacing="0">
		<thead>
			<tr>
				<th colspan="2">
					<xsl:choose>
						<xsl:when test="$is-holiday = 1">
							<xsl:attribute name="class">holiday</xsl:attribute>
							<xsl:value-of select="iCalendar/vcalendar[@x-wr-calname='Holidays']/vevent[substring(dtstart,5) = $this-month-day]/summary"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="class">session-date</xsl:attribute>
							
							<xsl:choose>
								<xsl:when test="normalize-space($week-day) = 'Monday'">
									<xsl:text>Session Length: </xsl:text>
									<xsl:value-of select="time-schedule/entry[weekday/@handle='monday']/session-length/item"/>
								</xsl:when>
								<xsl:when test="normalize-space($week-day) = 'Tuesday'">
									<xsl:text>Session Length: </xsl:text>
									<xsl:value-of select="time-schedule/entry[weekday/@handle='tuesday']/session-length/item"/>
								</xsl:when>
								<xsl:when test="normalize-space($week-day) = 'Wednesday'">
									<xsl:text>Session Length: </xsl:text>
									<xsl:value-of select="time-schedule/entry[weekday/@handle='wednesday']/session-length/item"/>
								</xsl:when>
								<xsl:when test="normalize-space($week-day) = 'Thursday'">
									<xsl:text>Session Length: </xsl:text>
									<xsl:value-of select="time-schedule/entry[weekday/@handle='thursday']/session-length/item"/>
								</xsl:when>
								<xsl:when test="normalize-space($week-day) = 'Friday'">
									<xsl:text>Session Length: </xsl:text>
									<xsl:value-of select="time-schedule/entry[weekday/@handle='friday']/session-length/item"/>
								</xsl:when>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</th>
			</tr>
		</thead>
		<tbody>
<!-- xxxx FIXIN' HERE xxxx -->
			<xsl:choose>
				<xsl:when test="normalize-space($week-day) = 'Monday' and time-schedule/entry[weekday/@handle='monday']/session-length/item/@handle = 'none' and /data/clients/entry/administrator = 'Yes'">
					<xsl:call-template name="show-blocked-day"/>
				</xsl:when>
				<xsl:when test="normalize-space($week-day) = 'Tuesday' and time-schedule/entry[weekday/@handle='tuesday']/session-length/item/@handle = 'none' and /data/clients/entry/administrator = 'Yes'">
					<xsl:call-template name="show-blocked-day"/>
				</xsl:when>
				<xsl:when test="normalize-space($week-day) = 'Wednesday' and time-schedule/entry[weekday/@handle='wednesday']/session-length/item/@handle = 'none' and /data/clients/entry/administrator = 'Yes'">
					<xsl:call-template name="show-blocked-day"/>
				</xsl:when>
				<xsl:when test="normalize-space($week-day) = 'Thursday' and time-schedule/entry[weekday/@handle='thursday']/session-length/item/@handle = 'none' and /data/clients/entry/administrator = 'Yes'">
					<xsl:call-template name="show-blocked-day"/>
				</xsl:when>
				<xsl:when test="normalize-space($week-day) = 'Friday' and time-schedule/entry[weekday/@handle='friday']/session-length/item/@handle = 'none' and /data/clients/entry/administrator = 'Yes'">
					<xsl:call-template name="show-blocked-day"/>
				</xsl:when>
				<xsl:when test="normalize-space($week-day) = 'Sunday' or normalize-space($week-day) = 'Saturday' and /data/clients/entry/administrator = 'Yes'">
					<tr>
						<td class="hour">
							<em>CLOSED</em>
						</td>
						<td>
							<dl class="blocked">
								<dd class="grid_6 omega">
									<div class="slot-blocked">We are closed on <strong>weekends</strong>.</div>
								</dd>
							</dl>
						</td>
					</tr>
				</xsl:when>
				<xsl:when test="/data/clients/entry/administrator = 'Yes'">
					<xsl:call-template name="calendar-day-hours"/>
				</xsl:when>
				<xsl:when test="normalize-space($today) = normalize-space($date)">
					<tr>
						<td class="hour">
							<em>TODAY</em>
						</td>
						<td>
							<dl class="blocked">
								<dd class="grid_6 omega">
									<div class="slot-blocked">Appointments can not be made or cancelled on <strong>"today's"</strong> date. If you'd like to make an appointment for today please call our office.</div>
								</dd>
							</dl>
						</td>
					</tr>
				</xsl:when>
				<xsl:when test="normalize-space($next-day) = normalize-space($date)">
					<tr>
						<td class="hour">
							<em>TOMORROW</em>
						</td>
						<td>
							<dl class="blocked">
								<dd class="grid_6 omega">
									<div class="slot-blocked">Appointments can only be made or cancelled a day in advance. Please select another day, or call our office directly.</div>
								</dd>
							</dl>
						</td>
					</tr>
				</xsl:when>
				<xsl:when test="normalize-space($is-past) = 1">
					<tr>
						<td class="hour">
							<em>BLOCKED</em>
						</td>
						<td>
							<dl class="blocked">
								<dd class="grid_6 omega">
									<div class="slot-blocked"><strong>Past</strong> appointments can not be altered.</div>
								</dd>
							</dl>
						</td>
					</tr>
				</xsl:when>
				<xsl:when test="normalize-space($week-day) = 'Sunday' or normalize-space($week-day) = 'Saturday'">
					<tr>
						<td class="hour">
							<em>CLOSED</em>
						</td>
						<td>
							<dl class="blocked">
								<dd class="grid_6 omega">
									<div class="slot-blocked">We are closed on <strong>weekends</strong>.</div>
								</dd>
							</dl>
						</td>
					</tr>
				</xsl:when>
				<xsl:when test="normalize-space($is-vacation) = 1">
					<tr>
						<td class="hour">
							<em>CLOSED</em>
						</td>
						<td>
							<dl class="blocked">
								<dd class="grid_6 omega">
									<div class="slot-closed"><strong><xsl:value-of select="vacations/entry[date-of-closure = normalize-space($date)]/reason-closed/item"/>:</strong> Appointments can not be made on this day as we are closed.</div>
								</dd>
							</dl>
						</td>
					</tr>
				</xsl:when>
				<!-- disable day if the time schedule has blocked this day from being active -->
				<xsl:when test="normalize-space($week-day) = 'Monday' and time-schedule/entry[weekday/@handle='monday']/session-length/item/@handle = 'none'">
					<xsl:call-template name="show-blocked-day"/>
				</xsl:when>
				<xsl:when test="normalize-space($week-day) = 'Tuesday' and time-schedule/entry[weekday/@handle='tuesday']/session-length/item/@handle = 'none'">
					<xsl:call-template name="show-blocked-day"/>
				</xsl:when>
				<xsl:when test="normalize-space($week-day) = 'Wednesday' and time-schedule/entry[weekday/@handle='wednesday']/session-length/item/@handle = 'none'">
					<xsl:call-template name="show-blocked-day"/>
				</xsl:when>
				<xsl:when test="normalize-space($week-day) = 'Thursday' and time-schedule/entry[weekday/@handle='thursday']/session-length/item/@handle = 'none'">
					<xsl:call-template name="show-blocked-day"/>
				</xsl:when>
				<xsl:when test="normalize-space($week-day) = 'Friday' and time-schedule/entry[weekday/@handle='friday']/session-length/item/@handle = 'none'">
					<xsl:call-template name="show-blocked-day"/>
				</xsl:when>
				<!-- disable day if the time schedule has blocked this day from being active -->
				<xsl:otherwise>
					<xsl:call-template name="calendar-day-hours"/>
				</xsl:otherwise>
			</xsl:choose>
		</tbody>
	</table>
</xsl:template>
<xsl:template name="show-blocked-day">
	<tr>
		<td class="hour">
			<em>BLOCKED</em>
		</td>
		<td>
			<dl class="blocked">
				<dd class="grid_6 omega">
					<div class="slot-blocked">This day is <strong>blocked</strong>.</div>
				</dd>
			</dl>
		</td>
	</tr>
</xsl:template>
<xsl:template name="calendar-day-hours">
	<xsl:param name="year" select="$year"/>
	<xsl:param name="month" select="$month"/>
	<xsl:param name="day" select="$day"/>
	<xsl:param name="date" select="concat($year,'-',$month,'-',$day)"/>
	<xsl:param name="week-day">
		<xsl:call-template name="get-day-of-the-week-name">
			<xsl:with-param name="date" select="$date"/>
		</xsl:call-template>
	</xsl:param>
	<!-- select the correct day's set appointment times -->
	<xsl:choose>
		<xsl:when test="normalize-space($week-day) = 'Monday'">
			<xsl:for-each select="time-schedule/entry[weekday/@handle='monday']/available-times/item">
				<xsl:sort select="@handle" data-type="text" order="ascending"/>
				<xsl:call-template name="show-day-times"/>
			</xsl:for-each>
		</xsl:when>
		<xsl:when test="normalize-space($week-day) = 'Tuesday'">
			<xsl:for-each select="time-schedule/entry[weekday/@handle='tuesday']/available-times/item">
				<xsl:sort select="@handle" data-type="text" order="ascending"/>
				<xsl:call-template name="show-day-times"/>
			</xsl:for-each>
		</xsl:when>
		<xsl:when test="normalize-space($week-day) = 'Wednesday'">
			<xsl:for-each select="time-schedule/entry[weekday/@handle='wednesday']/available-times/item">
				<xsl:sort select="@handle" data-type="text" order="ascending"/>
				<xsl:call-template name="show-day-times"/>
			</xsl:for-each>
		</xsl:when>
		<xsl:when test="normalize-space($week-day) = 'Thursday'">
			<xsl:for-each select="time-schedule/entry[weekday/@handle='thursday']/available-times/item">
				<xsl:sort select="@handle" data-type="text" order="ascending"/>
				<xsl:call-template name="show-day-times"/>
			</xsl:for-each>
		</xsl:when>
		<xsl:when test="normalize-space($week-day) = 'Friday'">
			<xsl:for-each select="time-schedule/entry[weekday/@handle='friday']/available-times/item">
				<xsl:sort select="@handle" data-type="text" order="ascending"/>
				<xsl:call-template name="show-day-times"/>
			</xsl:for-each>
		</xsl:when>
	</xsl:choose>
</xsl:template>
<xsl:template name="show-day-times">
	<tr>
		<td class="hour">
			<em>
				<!--xsl:value-of select="."/-->
				<xsl:call-template name="get-formatted-time">
					<xsl:with-param name="time" select="."/>
				</xsl:call-template>
			</em>
		</td>
		<td>
			<xsl:call-template name="day-display-appointments"/>
		</td>
	</tr>
</xsl:template>
<!-- when an appointment doesn't exist allow the ability to make an appointment for that time,
otherwise indicate that an appointment exists at that time -->
<xsl:template name="day-display-appointments">
	<xsl:param name="date" select="concat($year,'-',$month,'-',$day)"/>
	<xsl:param name="time" select="concat($date,' ',.)"/>
	<xsl:param name="time-t" select="substring($time,12,16)"/>
	<!--xsl:param name="app-date" select="substring($app-dtstart,1,10)"/-->
	<xsl:param name="app-d" select="/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/appointment-date"/>
	<xsl:param name="app-t" select="/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/appointment-date/@time"/>
	<xsl:param name="app-dt" select="concat($app-d,' ',$app-t)"/>
	
	<xsl:param name="clientfn" select="/data/clients/entry/first-name"/>
	<xsl:param name="clientln" select="/data/clients/entry/last-name"/>
	
	<xsl:param name="format-time">
		<xsl:call-template name="get-formatted-time">
			<xsl:with-param name="time" select="$time-t"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="format-month">
		<xsl:call-template name="get-formatted-month">
			<xsl:with-param name="month" select="$month"/>
			<xsl:with-param name="format-type" select="'long'"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="format-day">
		<xsl:call-template name="get-formatted-day">
			<xsl:with-param name="day" select="$day"/>
			<xsl:with-param name="format-type" select="'long'"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="format-week-day">
		<xsl:call-template name="get-day-of-the-week-name">
			<xsl:with-param name="date" select="$date"/>
		</xsl:call-template>
	</xsl:param>
<!-- xxxx FIXIN' HERE xxxx -->
	<!--xsl:param name="client-id" select="/data/admin-clients[entry/email-address = /data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/email]/entry/@id"/-->
	
	<xsl:choose>
		<xsl:when test="/data/clients/entry/administrator = 'Yes'">
			<xsl:choose>
				<xsl:when test="$app-dt = $time">
					<form id="delete-apt-{/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/@id}" class="make-appointment" action="" method="post">
						<dl>
							<dt class="grid_3 alpha">
								<input name="id" value="{/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/@id}" type="hidden" />
								<input class="appointment-button" name="action[delete-apt]" type="image" src="{$workspace}/css/img/button_cancel_apt.png" value="Cancel Appointment" />
							</dt>
							<dd class="grid_6 omega">
								<div class="slot-filled">
									<xsl:text>Time Slot </xsl:text>
									<em>Filled</em>
									<xsl:text> by </xsl:text>
<!-- xxxx FIXIN' HERE xxxx -->
									<!--a href="{$root}/admin-clients/" title="{/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/name}: {/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/email}">
										<xsl:value-of select="/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/name"/-->
										<xsl:value-of select="/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/name"/>
								</div>
							</dd>
						</dl>
					</form>
				</xsl:when>
				<xsl:otherwise>
					<form class="make-appointment" action="" method="post">
						<dl>
							<dt class="grid_3 alpha">
								<input class="make-apt appointment-button" id="make-apt_{substring(translate($time,' :','-'),12,5)}" name="action[make-appointment]" type="image" src="{$workspace}/css/img/button_make_apt.png" value="Make Appointment" />
								<img class="make-apt-faded on" id="make-apt-faded_{substring(translate($time,' :','-'),12,5)}" src="{$workspace}/css/img/button_make_apt_faded.png" alt="Select a client to make an appointment" />
								<input name="fields[appointment-date]" value="{$time}" type="hidden" />
								<input name="fields[payment-status]" value="Pending" type="hidden" />
								<input name="fields[payment-method]" value="None" type="hidden" />
								<input id="admin-name_{substring(translate($time,' :','-'),12,5)}" name="fields[name]" value="" type="hidden" />
								<input id="admin-email_{substring(translate($time,' :','-'),12,5)}" name="fields[email]" value="" type="hidden" />
								<input id="admin-reflection-email_{substring(translate($time,' :','-'),12,5)}" name="fields[reflection-email]" value="" type="hidden" />
								<input name="redirect" value="{$root}/calendar/day/{$year}/{$month}/{$day}" type="hidden" />
								<input name="send-email[sender-email]" value="noreply@corvallispt.net" type="hidden" />
								<input name="send-email[subject]" value="Your upcoming reservation" type="hidden" />
								<input name="send-email[body]" value="You've made an appointment with {normalize-space($website-name)} on {normalize-space($format-week-day)} {normalize-space($format-month)} {normalize-space($format-day)}, {normalize-space($year)} at {normalize-space($format-time)}" type="hidden" />
<!-- provide client email here -->
								<input id="client-email_{substring(translate($time,' :','-'),12,5)}" name="send-email[recipient]" value="" type="hidden" />
							</dt>
							<dd class="grid_6 omega">
								<div class="slot-available">
									<select class="admin_client_select" id="{substring(translate($time,' :','-'),12,5)}">
										<option value="Select Client">Select Client</option>
										<option disabled="disabled" value="">-----------</option>
										<xsl:apply-templates select="/data/admin-clients/entry"/>
									</select>
								</div>
							</dd>
						</dl>
					</form>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:when>
		<xsl:otherwise>
			<xsl:choose>
				<xsl:when test="$app-dt = $time">
					<form id="delete-apt-{/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/@id}" class="make-appointment" action="" method="post">
						<dl>
							<xsl:if test="/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/email = //front-end-authentication/@user">
								<dt class="grid_3 alpha">
									<input name="id" value="{/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/@id}" type="hidden" />
									<input class="appointment-button" name="action[delete-apt]" type="image" src="{$workspace}/css/img/button_cancel_apt.png" value="Cancel Appointment" />
								</dt>
							</xsl:if>
							<dd class="grid_6 omega">
								<div class="slot-filled">
									<xsl:text>Time Slot </xsl:text>
									<em>Filled</em>
									<xsl:if test="/data/appointments/entry[appointment-date=$date and appointment-date/@time=$time-t]/email = //front-end-authentication/@user">
										<xsl:text> by You</xsl:text>
									</xsl:if>
								</div>
							</dd>
						</dl>
					</form>
				</xsl:when>
				<xsl:otherwise>
					<xsl:if test="//front-end-authentication/@status = 'authenticated'">
						<form class="make-appointment" action="" method="post">
							<dl>
								<dt class="grid_3 alpha">
									<input class="appointment-button" name="action[make-appointment]" type="image" src="{$workspace}/css/img/button_make_apt.png" value="Make Appointment" />
									<input name="fields[appointment-date]" value="{$time}" type="hidden" />
									<input name="fields[payment-status]" value="Pending" type="hidden" />
									<input name="fields[name]" value="{$clientln}, {$clientfn}" type="hidden" />
									<input name="fields[email]" value="{//front-end-authentication/@user}" type="hidden" />
									<input name="fields[reflection-email]" value="{$client-ref}" type="hidden" />
									<input name="redirect" value="{$root}/calendar/{$year}/{$month}/{$day}" type="hidden" />
									<input name="send-email[sender-email]" value="noreply@corvallispt.net" type="hidden" />
									<input name="send-email[subject]" value="Your upcoming reservation" type="hidden" />
									<input name="send-email[body]" value="{$clientfn} {$clientln}, you've made an appointment with {normalize-space($website-name)} on {normalize-space($format-week-day)} {normalize-space($format-month)} {normalize-space($format-day)}, {normalize-space($year)} at {normalize-space($format-time)}" type="hidden" />
									<input name="send-email[recipient]" value="{//front-end-authentication/@user}" type="hidden" />
								</dt>
								<dd class="grid_6 omega">
									<div class="slot-available">Time Slot <em>Available</em></div>
								</dd>
							</dl>
						</form>
					</xsl:if>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="/data/admin-clients/entry">
	<option value="{email-address}">
		<xsl:value-of select="last-name"/>
		<xsl:text>, </xsl:text>
		<xsl:value-of select="first-name"/>
	</option>
</xsl:template>

<xsl:template name="month-days">
	<xsl:param name="date"/>
	<xsl:param name="year" select="substring($date,1,4)"/>
	<xsl:param name="month" select="substring($date,6,2)"/>
	<xsl:param name="month-int" select="format-number($month,'0')"/>
	<xsl:param name="leap-year">
		<xsl:call-template name="is-leap-year">
			<xsl:with-param name="year" select="$year"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:choose>
		<xsl:when test="$month-int!=2">
			<xsl:value-of select="/data/calendar/year/month[@value=$month-int]/@days"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:choose>
				<xsl:when test="$leap-year!=1">
					<xsl:value-of select="/data/calendar/year/month[@value=2]/@days"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="/data/calendar/year/month[@value=2]/@leap-year-days"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template name="previous-month">
	<xsl:param name="date"/>
	<xsl:param name="year" select="substring($date,1,4)"/>
	<xsl:param name="month" select="substring($date,6,2)"/>
	<xsl:choose>
		<xsl:when test="$month - 1 &lt; 1">12</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="format-number($month - 1,'00')"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template name="next-month">
	<xsl:param name="date"/>
	<xsl:param name="year" select="substring($date,1,4)"/>
	<xsl:param name="month" select="substring($date,6,2)"/>
	<xsl:choose>
		<xsl:when test="$month + 1 &gt; 12">01</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="format-number($month + 1,'00')"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template name="previous-month-year">
	<xsl:param name="date"/>
	<xsl:param name="year" select="substring($date,1,4)"/>
	<xsl:param name="month" select="substring($date,6,2)"/>
	<xsl:choose>
		<xsl:when test="$month != 1">
			<xsl:value-of select="$year"/>
		</xsl:when>
		<xsl:when test="$month = 1">
			<xsl:value-of select="$year - 1"/>
		</xsl:when>
		<xsl:otherwise>0</xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template name="next-month-year">
	<xsl:param name="date"/>
	<xsl:param name="year" select="substring($date,1,4)"/>
	<xsl:param name="month" select="substring($date,6,2)"/>
	<xsl:choose>
		<xsl:when test="$month &lt; 12">
			<xsl:value-of select="$year"/>
		</xsl:when>
		<xsl:when test="$month = 12">
			<xsl:value-of select="$year + 1"/>
		</xsl:when>
		<xsl:otherwise>0</xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template name="previous-day">
	<xsl:param name="date"/>
	<xsl:param name="year" select="substring($date,1,4)"/>
	<xsl:param name="month" select="substring($date,6,2)"/>
	<xsl:param name="day" select="substring($date,9,2)"/>
	<xsl:param name="previous-month">
		<xsl:call-template name="previous-month">
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="previous-month-year">
		<xsl:call-template name="previous-month-year">
			<xsl:with-param name="year" select="$year"/>
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="previous-month-days">
		<xsl:call-template name="month-days">
			<xsl:with-param name="year" select="$previous-month-year"/>
			<xsl:with-param name="month" select="$previous-month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:choose>
		<xsl:when test="$day - 1 &lt; 1 and $month = 1">
			<xsl:value-of select="concat($previous-month-year,'-',$previous-month,'-',format-number($previous-month-days,'00'))"/>
		</xsl:when>
		<xsl:when test="$day - 1 &lt; 1 and $month &gt; 1">
			<xsl:value-of select="concat($year,'-',$previous-month,'-',format-number($previous-month-days,'00'))"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="concat($year,'-',$month,'-',format-number($day - 1,'00'))"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template name="next-day">
	<xsl:param name="date"/>
	<xsl:param name="year" select="substring($date,1,4)"/>
	<xsl:param name="month" select="substring($date,6,2)"/>
	<xsl:param name="day" select="substring($date,9,2)"/>
	<xsl:param name="month-days">
		<xsl:call-template name="month-days">
			<xsl:with-param name="year" select="$year"/>
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="next-month">
		<xsl:call-template name="next-month">
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="next-month-year">
		<xsl:call-template name="next-month-year">
			<xsl:with-param name="year" select="$year"/>
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:choose>
		<xsl:when test="$day + 1 &gt; $month-days">
			<xsl:value-of select="concat($next-month-year,'-',$next-month,'-01')"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="concat($year,'-',$month,'-',format-number($day + 1,'00'))"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template name="previous-week">
	<xsl:param name="date"/>
	<xsl:param name="year" select="substring($date,1,4)"/>
	<xsl:param name="month" select="substring($date,6,2)"/>
	<xsl:param name="day" select="substring($date,9,2)"/>
	<xsl:param name="previous-month">
		<xsl:call-template name="previous-month">
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="previous-month-year">
		<xsl:call-template name="previous-month-year">
			<xsl:with-param name="year" select="$year"/>
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="previous-month-days">
		<xsl:call-template name="month-days">
			<xsl:with-param name="year" select="$previous-month-year"/>
			<xsl:with-param name="month" select="$previous-month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:choose>
		<xsl:when test="$day - 7 &lt; 1 and $month = 1">
			<xsl:value-of select="concat($previous-month-year,'-',$previous-month,'-',format-number($previous-month-days - (7 - $day),'00'))"/>
		</xsl:when>
		<xsl:when test="$day - 7 &lt; 1 and $month &gt; 1">
			<xsl:value-of select="concat($year,'-',$previous-month,'-',format-number($previous-month-days - (7 - $day),'00'))"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="concat($year,'-',$month,'-',format-number($day - 7,'00'))"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template name="next-week">
	<xsl:param name="date"/>
	<xsl:param name="year" select="substring($date,1,4)"/>
	<xsl:param name="month" select="substring($date,6,2)"/>
	<xsl:param name="day" select="substring($date,9,2)"/>
	<xsl:param name="month-days">
		<xsl:call-template name="month-days">
			<xsl:with-param name="year" select="$year"/>
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="next-month">
		<xsl:call-template name="next-month">
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="next-month-year">
		<xsl:call-template name="next-month-year">
			<xsl:with-param name="year" select="$year"/>
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:choose>
		<xsl:when test="$day + 7 &gt; $month-days">
			<xsl:value-of select="concat($next-month-year,'-',$next-month,'-',format-number($day + 7 - $month-days,'00'))"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="concat($year,'-',$month,'-',format-number($day + 7,'00'))"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template name="previous-month-days">
	<xsl:param name="date"/>
	<xsl:param name="year" select="substring($date,1,4)"/>
	<xsl:param name="month" select="substring($date,6,2)"/>
	<xsl:param name="previous-month">
		<xsl:call-template name="previous-month">
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="leap-year">
		<xsl:call-template name="is-leap-year">
			<xsl:with-param name="year" select="$year"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:call-template name="month-days">
		<xsl:with-param name="leap-year" select="$leap-year"/>
		<xsl:with-param name="month" select="$previous-month"/>
	</xsl:call-template>
</xsl:template>
<xsl:template name="next-month-days">
	<xsl:param name="date"/>
	<xsl:param name="year" select="substring($date,1,4)"/>
	<xsl:param name="month" select="substring($date,6,2)"/>
	<xsl:param name="next-month">
		<xsl:call-template name="next-month">
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="leap-year">
		<xsl:call-template name="is-leap-year">
			<xsl:with-param name="year" select="$year"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:call-template name="month-days">
		<xsl:with-param name="leap-year" select="$leap-year"/>
		<xsl:with-param name="month" select="$next-month"/>
	</xsl:call-template>
</xsl:template>
<xsl:template name="week-number">
	<xsl:param name="date" select="$today"/>
	<xsl:param name="year" select="substring($date, 1, 4)" />
	<xsl:param name="leap" select="(not($year mod 4) and $year mod 100) or not($year mod 400)" />
	<xsl:param name="month" select="substring($date, 6, 2)" />
	<xsl:param name="day" select="substring($date, 9, 2)" />
	<xsl:param name="month-days">
		<xsl:call-template name="month-days">
			<xsl:with-param name="leap-year" select="$leap"/>
			<xsl:with-param name="month" select="$month"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="days">
		<xsl:choose>
			<xsl:when test="$leap and $month > 2">
				<xsl:value-of select="$month-days + $day + 1" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$month-days + $day" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:param>
	<xsl:param name="y-1" select="$year - 1" />
	<xsl:param name="day-of-week" 
      select="(($y-1 + floor($y-1 div 4) -
           floor($y-1 div 100) + floor($y-1 div 400) +
           $days) 
           mod 7) + 1" />
	<xsl:choose>
		<xsl:when test="($day - $day-of-week) mod 7">
			<xsl:value-of select="floor(($day - $day-of-week) div 7) + 2" />
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="floor(($day - $day-of-week) div 7) + 1" />
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
</xsl:stylesheet>
